package main

import (
	"fmt"
	"time"
)

func main() {
	messages := make(chan int, 10)

	// 消费者
	go func() {
		ticker := time.NewTicker(time.Second * 2)
		for range ticker.C {
			select {
			case m := <-messages:
				fmt.Println(m)
			}
		}
	}()

	// 生产者
	go func() {
		ticker := time.NewTicker(time.Second * 1)
		for i := range ticker.C {
			messages <- i.Second()
		}
	}()

	time.Sleep(time.Second * 10)
}
